/****************************************************************************************************************************************************************
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                      _____  ___________                   ___    ______      ______           _____     _______________________                              *
 *                      __  / / /__  /_  /_____________ _    __ |  / /__(_)________  /_____________  /_    ___    |_____/_/__  __ \                             *
 *                      _  / / /__  /_  __/_  ___/  __ `/    __ | / /__  /_  __ \_  /_  _ \_  __ \  __/    __  /| |___/_/ __  / / /                             *
 *                      / /_/ / _  / / /_ _  /   / /_/ /     __ |/ / _  / / /_/ /  / /  __/  / / / /_      _  ___ |_/_/   _  /_/ /                              *
 *                      \____/  /_/  \__/ /_/    \__,_/      _____/  /_/  \____//_/  \___//_/ /_/\__/      /_/  |_/_/     /_____/                               *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @Project: Ultra Violent - Attack and Defend                                                                                                             *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @Author: Daniel "thiaZ" Koenen                                                                                                                          *
 *          @Used content                                                                                                                                       *
 *              @sscanf Plugin, foreach, Whirlpool Plugin, YSI - Y_Less                                                                                         *
 *              @zcmd - Zeex                                                                                                                                    *
 *              @Streamer Plugin, IRC Plugin - Incognito                                                                                                        *
 *              @dini - Dracoblue                                                                                                                               *
 *              @MySQL Plugin - G-sTyLeZzZ                                                                                                                      *
 *          @Special thanks to                                                                                                                                  *
 *              @Slice                                                                                                                                          *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @File: uvaad.pwn - Main File                                                                                                                            *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @This file is not released under any open source licence, you are not allowed to own this file except you have the author's permission.                 *
 *                                                                                                                                                              *
 *                                                                                                                                                              *
 *      @copyright (c) Daniel "thiaZ" Koenen 2010 - 2011 - danielkoenen@t-online.de                                                                             *
 *                                                                                                                                                              *
 ****************************************************************************************************************************************************************/          

#define STR_MAIN        "Teams\nSkins\nBase\nWeapon Config\nReset Configuration"
#define STR_TEAMS       "Home (%s)\nAway (%s)"
#define STR_SKINS       "Home (%d)\nAway (%d)\nReferee (%d)"
#define STR_BASE        "Maximal score (%d)\nPrepare time (%d)\nCP size (%d)\nCP time (%d)\nRound time (%d)\nCar spawn limit (%d)\nCar spawn distance (%.2f)\nTag Drawdistance (%.2f)"
#define STR_WEAPON      "Sets\nRestrictions"
#define STR_HOMENAME    "Enter the value you want homeName\nto be changed to and press Update."
#define STR_AWAYNAME    "Enter the value you want awayName\nto be changed to and press Update."
#define STR_HOMESKIN    "Enter the value you want homeSkin\nto be changed to and press Update."
#define STR_AWAYSKIN    "Enter the value you want awaySkin\nto be changed to and press Update."
#define STR_REFSKIN     "Enter the value you want refSkin\nto be changed to and press Update."

#define STR_MAXSCORE    "Enter the value you want maxScore\nto be changed to and press Update."
#define STR_PREPTIME    "Enter the value you want basePrepare\nto be changed to and press Update."
#define STR_CPSIZE      "Enter the value you want baseCPSize\nto be changed to and press Update."
#define STR_CPTIME      "Enter the value you want baseCPTime\nto be changed to and press Update."
#define STR_ROUNDTME    "Enter the value you want baseRoundTime\nto be changed to and press Update."
#define STR_CARSPWN     "Enter the value you want baseCarSpawn\nto be changed to and press Update."
#define STR_CARSPWND    "Enter the value you want baseCarSpawnDis\nto be changed to and press Update."
#define STR_TAGDRAW     "Enter the value you want baseTagDraw\nto be changed to and press Update."
#define STR_WSETS2      "Enter the weapon ID's you want this set to be\nchanged to. (Format: w1,w2)"
#define STR_WRES2       "Enter the number of weapons\nyou want to have per team. (0 = infinite)"

Hook:CConfig_OnGameModeInit()
{
    CConfig::load();
    return true;
}

Hook:CConfig_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_CONFIG_MAIN:
        {
            if(!response)
            {
                return true;
            }
            
            switch(listitem)
            {
                case 0: CConfig::showDialog(playerid, DIALOG_CONFIG_TEAMS);
                case 1: CConfig::showDialog(playerid, DIALOG_CONFIG_SKINS);
                case 2: CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                case 3: CConfig::showDialog(playerid, DIALOG_CONFIG_WEAPON);
                case 4: 
                {
                    format(gameConfig[homeName], 24, "UvH");
                    format(gameConfig[awayName], 24, "Away");
                    
                    gameConfig[teamSkin][TEAM_HOME] = 230;
                    gameConfig[teamSkin][TEAM_AWAY] = 134;
                    gameConfig[teamSkin][TEAM_REF] = 167;
                    CPlayer::reloadSkins();
                    
                    gameConfig[iMaxScore] = 10;
                    gameConfig[iPrepareTime] = 15;
                    gameConfig[iCPSize] = 2;
                    gameConfig[iCPCount] = 15;
                    gameConfig[iBaseTime] = 10;
                    gameConfig[iCarSpawnMax] = 2;
                    gameConfig[fCarSpawnDis] = 150.0;
                    
                    gameConfig[fTagDrawDis] = 20.0;
                    SetNameTagDrawDistance(gameConfig[fTagDrawDis]);
                    
                    new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
                    INI_SetTag(configFile, "Teams");
                    INI_WriteString(configFile, "homeName", gameConfig[homeName]);
                    INI_WriteString(configFile, "awayName", gameConfig[awayName]);
                    
                    INI_SetTag(configFile, "Skins");
                    INI_WriteInt(configFile, "homeSkin", gameConfig[teamSkin][TEAM_HOME]);
                    INI_WriteInt(configFile, "awaySkin", gameConfig[teamSkin][TEAM_AWAY]);
                    
                    INI_SetTag(configFile, "Game");
                    INI_WriteInt(configFile, "maxScore", gameConfig[iMaxScore]);
                    INI_WriteInt(configFile, "basePrepare", gameConfig[iPrepareTime]);
                    INI_WriteInt(configFile, "baseCPSize", gameConfig[iCPSize]);
                    INI_WriteInt(configFile, "baseCPTime", gameConfig[iCPCount]);
                    INI_WriteInt(configFile, "baseRoundTime", gameConfig[iBaseTime]);
                    INI_WriteInt(configFile, "baseCarSpawn", gameConfig[iCarSpawnMax]);
                    INI_WriteFloat(configFile, "baseCarSpawnDis", gameConfig[fCarSpawnDis]);
                    INI_WriteFloat(configFile, "baseTagDraw", gameConfig[fTagDrawDis]);
                    INI_Close(configFile);
                    
                    SendClientMessageToAll(C_YELLOW, "The configuration has been resetted to its default values.");
                }   
            }
        }
        
        case DIALOG_CONFIG_TEAMS:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_MAIN);
                return true;
            }
            
            switch(listitem)
            {
                case 0: CConfig::showDialog(playerid, DIALOG_CONFIG_HOMENAME);
                case 1: CConfig::showDialog(playerid, DIALOG_CONFIG_AWAYNAME);
            }
        }
        
        case DIALOG_CONFIG_HOMENAME:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_TEAMS);
                return true;
            }
            
            if(strlen(inputtext) == 0)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_HOMENAME);
                return true;
            }
            
            if(strlen(inputtext) > 4)
            {
                SendClientMessage(playerid, C_RED, "* Error: Team names may not be longer than 4 characters.");
                CConfig::showDialog(playerid, DIALOG_CONFIG_HOMENAME);
                return true;
            }
            
            format(gameConfig[homeName], 24, "%s", inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Teams");
            INI_WriteString(configFile, "homeName", inputtext);
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field homeName changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_AWAYNAME:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_TEAMS);
                return true;
            }
            
            if(strlen(inputtext) == 0)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_AWAYNAME);
                return true;
            }
            
            if(strlen(inputtext) > 4)
            {
                SendClientMessage(playerid, C_RED, "* Error: Team names may not be longer than 4 characters.");
                CConfig::showDialog(playerid, DIALOG_CONFIG_HOMENAME);
                return true;
            }
            
            format(gameConfig[awayName], 24, "%s", inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Teams");
            INI_WriteString(configFile, "awayName", inputtext);
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field awayName changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_SKINS:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_MAIN);
                return true;
            }
            
            switch(listitem)
            {
                case 0: CConfig::showDialog(playerid, DIALOG_CONFIG_HOMESKIN);
                case 1: CConfig::showDialog(playerid, DIALOG_CONFIG_AWAYSKIN);
                case 2: CConfig::showDialog(playerid, DIALOG_CONFIG_REFSKIN);
            }
        }
            
        case DIALOG_CONFIG_HOMESKIN:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_SKINS);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_HOMESKIN);
                return true;
            }
            
            if(!isValidSkin(strval(inputtext)))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_HOMESKIN);
                SendClientMessage(playerid, C_RED, "* Error: Invalid skin ID.");
                return true;
            }
            
            gameConfig[teamSkin][TEAM_HOME] = strval(inputtext);
            CPlayer::reloadSkins();
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Skins");
            INI_WriteInt(configFile, "homeSkin", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field homeSkin changed to %s, use '/s' if you can't move.", inputtext);
        }
        
        case DIALOG_CONFIG_AWAYSKIN:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_SKINS);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_AWAYSKIN);
                return true;
            }
            
            if(!isValidSkin(strval(inputtext)))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_AWAYSKIN);
                SendClientMessage(playerid, C_RED, "* Error: Invalid skin ID.");
                return true;
            }
            
            gameConfig[teamSkin][TEAM_AWAY] = strval(inputtext);
            CPlayer::reloadSkins();
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Skins");
            INI_WriteInt(configFile, "awaySkin", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field awaySkin changed to %s, use '/s' if you can't move.", inputtext);
        }
        
        case DIALOG_CONFIG_REFSKIN:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_SKINS);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_REFSKIN);
                return true;
            }
            
            if(!isValidSkin(strval(inputtext)))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_REFSKIN);
                SendClientMessage(playerid, C_RED, "* Error: Invalid skin ID.");
                return true;
            }
            
            gameConfig[teamSkin][TEAM_REF] = strval(inputtext);
            CPlayer::reloadSkins();
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Skins");
            INI_WriteInt(configFile, "refSkin", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field refSkin changed to %s, use '/s' if you can't move.", inputtext);
        }
        
        case DIALOG_CONFIG_BASE:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_MAIN);
                return true;
            }
            
            switch(listitem)
            {
                case 0: CConfig::showDialog(playerid, DIALOG_CONFIG_MAXSCORE);
                case 1: CConfig::showDialog(playerid, DIALOG_CONFIG_PREPTIME);
                case 2: CConfig::showDialog(playerid, DIALOG_CONFIG_CPSIZE);
                case 3: CConfig::showDialog(playerid, DIALOG_CONFIG_CPTIME);
                case 4: CConfig::showDialog(playerid, DIALOG_CONFIG_ROUNDTME);
                case 5: CConfig::showDialog(playerid, DIALOG_CONFIG_CARSPWN);
                case 6: CConfig::showDialog(playerid, DIALOG_CONFIG_CARSPWND);
                case 7: CConfig::showDialog(playerid, DIALOG_CONFIG_TAGDRAW);
            }
        }
        
        case DIALOG_CONFIG_MAXSCORE:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_MAXSCORE);
                return true;
            }
            
            gameConfig[iMaxScore] = strval(inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Game");
            INI_WriteInt(configFile, "maxScore", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field maxScore changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_PREPTIME:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_PREPTIME);
                return true;
            }
            
            gameConfig[iPrepareTime] = strval(inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Game");
            INI_WriteInt(configFile, "basePrepare", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field basePrepare changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_CPSIZE:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_CPSIZE);
                return true;
            }
            
            gameConfig[iCPSize] = strval(inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Game");
            INI_WriteInt(configFile, "baseCPSize", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field baseCPSize changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_CPTIME:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_CPTIME);
                return true;
            }
            
            gameConfig[iCPCount] = strval(inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Game");
            INI_WriteInt(configFile, "baseCPTime", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field baseCPTime changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_ROUNDTME:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_ROUNDTME);
                return true;
            }
            
            gameConfig[iBaseTime] = strval(inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Game");
            INI_WriteInt(configFile, "baseRoundTime", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field baseRoundTime changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_CARSPWN:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_CARSPWN);
                return true;
            }
            
            gameConfig[iCarSpawnMax] = strval(inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Game");
            INI_WriteInt(configFile, "baseCarSpawn", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field baseCarSpawn changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_CARSPWND:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_CARSPWND);
                return true;
            }
            
            gameConfig[fCarSpawnDis] = floatstr(inputtext);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Game");
            INI_WriteInt(configFile, "baseCarSpawnDis", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field baseCarSpawn changed to %s.", inputtext);
        }
        
        case DIALOG_CONFIG_TAGDRAW:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_BASE);
                return true;
            }
            
            if(strlen(inputtext) == 0 || !isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_TAGDRAW);
                return true;
            }
            
            gameConfig[fTagDrawDis] = floatstr(inputtext);
            SetNameTagDrawDistance(gameConfig[fTagDrawDis]);
            
            new INI:configFile = INI_Open("/Uv_AAD/Config.ini");
            INI_SetTag(configFile, "Game");
            INI_WriteInt(configFile, "baseTagDraw", strval(inputtext));
            INI_Close(configFile);
            
            SendFormattedMessageToAll(C_YELLOW, "Value of field baseTagDraw changed to %s.", inputtext);
        }

        case DIALOG_CONFIG_WEAPON:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_MAIN);
                return true;
            }
            
            switch(listitem)
            {
                case 0: CConfig::showDialog(playerid, DIALOG_CONFIG_WSETS);
                case 1: CConfig::showDialog(playerid, DIALOG_CONFIG_WRES);
            }
        }
        
        case DIALOG_CONFIG_WSETS:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_WEAPON);
                return true;
            }
            
            playerData[playerid][weaponSelected] = listitem;
            CConfig::showDialog(playerid, DIALOG_CONFIG_WSETS2);
        }
        
        case DIALOG_CONFIG_WSETS2:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_WSETS);
                return true;
            }
            
            new iSet = playerData[playerid][weaponSelected],
                iWeapon[2], 
                sSet[7];
            
            if(sscanf(inputtext, "p<,>dd", iWeapon[0], iWeapon[1]))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_WSETS2);
                SendClientMessage(playerid, C_RED, "* Error: Wrong input format.");
                return true;
            }
            
            if(!isValidWeapon(iWeapon[0]), !isValidWeapon(iWeapon[1]))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_WSETS2);
                SendClientMessage(playerid, C_RED, "* Error: Invalid weapon ID(s).");
                return true;
            }
                
            
            weaponSets[iSet][0] = iWeapon[0];
            weaponSets[iSet][1] = iWeapon[1];
            
            format(sSet, 7, "set_%d", iSet);
            new INI:weaponConfig = INI_Open("/Uv_AAD/WeaponConfig.ini");
            INI_SetTag(weaponConfig, "Sets");
            INI_WriteString(weaponConfig, sSet, inputtext);
            INI_Close(weaponConfig);
            
            playerData[playerid][weaponSelected] = -1;
            SendFormattedMessageToAll(C_YELLOW, "Value of field set_%d changed to %s.", iSet, inputtext);
        }   
        
        case DIALOG_CONFIG_WRES:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_WEAPON);
                return true;
            }
            
            playerData[playerid][restrictionSelected] = listitem;
            CConfig::showDialog(playerid, DIALOG_CONFIG_WRES2);
        }
        
        case DIALOG_CONFIG_WRES2:
        {
            if(!response)
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_WRES);
                return true;
            }
            
            new iWeapon = playerData[playerid][restrictionSelected],
                sKey[3];
                
            switch(iWeapon)
            {
                case 22 .. 34: iWeapon = (iWeapon + 3);
            }
            
            if(!isNumeric(inputtext))
            {
                CConfig::showDialog(playerid, DIALOG_CONFIG_WRES2);
                SendClientMessage(playerid, C_RED, "* Error: Invalid input.");
                return true;
            }
            
            weaponRestrictions[iWeapon] = strval(inputtext);
            
            format(sKey, 7, "%d", iWeapon);
            new INI:weaponConfig = INI_Open("/Uv_AAD/WeaponConfig.ini");
            INI_SetTag(weaponConfig, "Restrictions");
            INI_WriteString(weaponConfig, sKey, inputtext);
            INI_Close(weaponConfig);
            
            playerData[playerid][restrictionSelected] = -1;
            SendFormattedMessageToAll(C_YELLOW, "Value of field restriction_%d changed to %s.", iWeapon, inputtext);
        }
    }       
    
    return true;
}

forward onWeaponConfigLoad(tag[], name[], value[]);
public  onWeaponConfigLoad(tag[], name[], value[])
{
    if(!strcmp(tag, "Sets"))
    {
        new iSet = strval(name[4]);
        sscanf(value, "p<,>dd", weaponSets[iSet][0], weaponSets[iSet][1]);
    }
    
    if(!strcmp(tag, "Restrictions"))
    {
        new iWeapon = strval(name[0]);
        weaponRestrictions[iWeapon] = strval(value);
    }
    
    #if DEBUG == true 
        printf("[WEAPONSET] [%s] %s with value %s.", tag, name, value);
    #endif
    return true;
}

forward onConfigLoad(tag[], name[], value[]);
public  onConfigLoad(tag[], name[], value[])
{
    if(!strcmp(tag, "Teams"))
    {
        if(!strcmp(name, "homeName"))
        {
            format(gameConfig[homeName], 24, "%s", value);
        }
        
        if(!strcmp(name, "awayName"))
        {
            format(gameConfig[awayName], 24, "%s", value);
        }
    }
    
    if(!strcmp(tag, "Skins"))
    {
        if(!strcmp(name, "homeSkin"))
        {
            gameConfig[teamSkin][TEAM_HOME] = strval(value);
        }
        
        if(!strcmp(name, "awaySkin"))
        {
            gameConfig[teamSkin][TEAM_AWAY] = strval(value);
        }
        
        if(!strcmp(name, "refSkin"))
        {
            gameConfig[teamSkin][TEAM_REF] = strval(value);
        }
    }
    
    if(!strcmp(tag, "Game"))
    {
        if(!strcmp(name, "maxScore"))
        {
            gameConfig[iMaxScore] = strval(value);
        }
        
        if(!strcmp(name, "basePrepare"))
        {
            gameConfig[iPrepareTime] = strval(value);
        }
        
        if(!strcmp(name, "baseCPSize"))
        {
            gameConfig[iCPSize] = strval(value);
        }
        
        if(!strcmp(name, "baseCPTime"))
        {
            gameConfig[iCPCount] = strval(value);
        }
        
        if(!strcmp(name, "baseRoundTime"))
        {
            gameConfig[iBaseTime] = strval(value);
        }
        
        if(!strcmp(name, "baseCarSpawn"))
        {
            gameConfig[iCarSpawnMax] = strval(value);
        }
        
        if(!strcmp(name, "baseCarSpawnDis"))
        {
            gameConfig[fCarSpawnDis] = floatstr(value);
        }
        
        if(!strcmp(name, "baseTagDraw"))
        {
            gameConfig[fTagDrawDis] = floatstr(value);
            SetNameTagDrawDistance(gameConfig[fTagDrawDis]);
        }
    }
    
    #if DEBUG == true
        printf("[CONFIG] [%s] %s with value %s.", tag, name, value);
    #endif
    return false;
}

stock CConfig::showDialog(playerid, iDialog)
{
    new sTemp[1024];
    switch(iDialog)
    {
        case DIALOG_CONFIG_MAIN:        ShowPlayerDialog(playerid, DIALOG_CONFIG_MAIN, DIALOG_STYLE_LIST, "Configuration", STR_MAIN, "Continue", "Close");
        case DIALOG_CONFIG_WEAPON:      ShowPlayerDialog(playerid, DIALOG_CONFIG_WEAPON, DIALOG_STYLE_LIST, "Weapon", STR_WEAPON, "Continue", "Back");
        case DIALOG_CONFIG_HOMENAME:    ShowPlayerDialog(playerid, DIALOG_CONFIG_HOMENAME, DIALOG_STYLE_INPUT, "Teamname", STR_HOMENAME, "Update", "Back");
        case DIALOG_CONFIG_AWAYNAME:    ShowPlayerDialog(playerid, DIALOG_CONFIG_AWAYNAME, DIALOG_STYLE_INPUT, "Teamname", STR_AWAYNAME, "Update", "Back");
        case DIALOG_CONFIG_HOMESKIN:    ShowPlayerDialog(playerid, DIALOG_CONFIG_HOMESKIN, DIALOG_STYLE_INPUT, "Teamskin", STR_HOMESKIN, "Update", "Back");
        case DIALOG_CONFIG_AWAYSKIN:    ShowPlayerDialog(playerid, DIALOG_CONFIG_AWAYSKIN, DIALOG_STYLE_INPUT, "Teamskin", STR_AWAYSKIN, "Update", "Back");
        case DIALOG_CONFIG_REFSKIN:     ShowPlayerDialog(playerid, DIALOG_CONFIG_HOMESKIN, DIALOG_STYLE_INPUT, "Teamskin", STR_REFSKIN, "Update", "Back");
        case DIALOG_CONFIG_MAXSCORE:    ShowPlayerDialog(playerid, DIALOG_CONFIG_MAXSCORE, DIALOG_STYLE_INPUT, "Base", STR_MAXSCORE, "Update", "Back");
        case DIALOG_CONFIG_PREPTIME:    ShowPlayerDialog(playerid, DIALOG_CONFIG_PREPTIME, DIALOG_STYLE_INPUT, "Base", STR_PREPTIME, "Update", "Back");
        case DIALOG_CONFIG_CPSIZE:      ShowPlayerDialog(playerid, DIALOG_CONFIG_CPSIZE, DIALOG_STYLE_INPUT, "Base", STR_CPSIZE, "Update", "Back");
        case DIALOG_CONFIG_CPTIME:      ShowPlayerDialog(playerid, DIALOG_CONFIG_CPTIME, DIALOG_STYLE_INPUT, "Base", STR_CPTIME, "Update", "Back");
        case DIALOG_CONFIG_ROUNDTME:    ShowPlayerDialog(playerid, DIALOG_CONFIG_ROUNDTME, DIALOG_STYLE_INPUT, "Base", STR_ROUNDTME, "Update", "Back");
        case DIALOG_CONFIG_CARSPWN:     ShowPlayerDialog(playerid, DIALOG_CONFIG_CARSPWN, DIALOG_STYLE_INPUT, "Base", STR_CARSPWN, "Update", "Back");
        case DIALOG_CONFIG_CARSPWND:    ShowPlayerDialog(playerid, DIALOG_CONFIG_CARSPWND, DIALOG_STYLE_INPUT, "Base", STR_CARSPWND, "Update", "Back");
        case DIALOG_CONFIG_TAGDRAW:     ShowPlayerDialog(playerid, DIALOG_CONFIG_TAGDRAW, DIALOG_STYLE_INPUT, "Base", STR_TAGDRAW, "Update", "Back");
        case DIALOG_CONFIG_WSETS2:      ShowPlayerDialog(playerid, DIALOG_CONFIG_WSETS2, DIALOG_STYLE_INPUT, "Weaponsets", STR_WSETS2, "Update", "Back");
        case DIALOG_CONFIG_WRES2:       ShowPlayerDialog(playerid, DIALOG_CONFIG_WRES2, DIALOG_STYLE_INPUT, "Weapon Restrictions", STR_WRES2, "Update", "Back");
        
        case DIALOG_CONFIG_WSETS:
        {
            new sTemp_2[40];
            for(new i; i < MAX_WEAPONSETS; i++)
            {
                format(sTemp_2, 40, "#%d - %s, %s", i, getWeaponNameEx(weaponSets[i][0]), getWeaponNameEx(weaponSets[i][1]));
                format(sTemp, 1024, "%s\n%s", sTemp, sTemp_2);
            }
            
            ShowPlayerDialog(playerid, DIALOG_CONFIG_WSETS, DIALOG_STYLE_LIST, "Weaponsets", sTemp, "Continue", "Back");
        }
        
        case DIALOG_CONFIG_WRES:
        {
            new sTemp_2[32];
            for(new i; i < 35; i++)
            {
                if(isValidWeapon(i))
                {
                    format(sTemp_2, 32, "%s (%d)", getWeaponNameEx(i), weaponRestrictions[i]);
                    format(sTemp, 1024, "%s\n%s", sTemp, sTemp_2);
                }
            }
            
            ShowPlayerDialog(playerid, DIALOG_CONFIG_WRES, DIALOG_STYLE_LIST, "Weapon Restrictions", sTemp, "Continue", "Back");
        }
                
        case DIALOG_CONFIG_TEAMS: 
        {
            format(sTemp, 1024, STR_TEAMS, gameConfig[homeName], gameConfig[awayName]);
            ShowPlayerDialog(playerid, DIALOG_CONFIG_TEAMS, DIALOG_STYLE_LIST, "Teams", sTemp, "Continue", "Back");
        }
                
        case DIALOG_CONFIG_SKINS:
        {
            format(sTemp, 1024, STR_SKINS, gameConfig[teamSkin][TEAM_HOME], gameConfig[teamSkin][TEAM_AWAY], gameConfig[teamSkin][TEAM_REF]);
            ShowPlayerDialog(playerid, DIALOG_CONFIG_SKINS, DIALOG_STYLE_LIST, "Skins", sTemp, "Continue", "Back");
        }
                
        case DIALOG_CONFIG_BASE:
        {
            format(sTemp, 1024, STR_BASE, gameConfig[iMaxScore],
                                           gameConfig[iPrepareTime],
                                           gameConfig[iCPSize],
                                           gameConfig[iCPCount],
                                           gameConfig[iBaseTime],
                                           gameConfig[iCarSpawnMax],
                                           gameConfig[fCarSpawnDis],
                                           gameConfig[fTagDrawDis]);
                                                   
            ShowPlayerDialog(playerid, DIALOG_CONFIG_BASE, DIALOG_STYLE_LIST, "Base", sTemp, "Continue", "Back");
        }
    }
    
    return true;
}

stock CConfig::load()
{
    INI_ParseFile("/Uv_AAD/Config.ini", "onConfigLoad", .bPassTag = true);
    INI_ParseFile("/Uv_AAD/WeaponConfig.ini", "onWeaponConfigLoad", .bPassTag = true);
    return true;
}
    
